import { z } from "zod";
import { TFunction } from "./common";

export const UpdateProfileSchema = (t: TFunction) =>
  z.object({
    id: z.string().min(1, { message: t("idRequired") }),
    name: z.string(),
    first_name: z.string(),
    last_name: z.string(),
    mobile: z.string(),
    region: z.string(),
    address: z.string(),
    image: z.string(),
  });

export type UpdateProfileFormData = z.infer<
  ReturnType<typeof UpdateProfileSchema>
>;

export const UpdateProfilePasswordSchema = (t: TFunction) =>
  z
    .object({
      id: z.string().min(1, { message: t("passwordInvalid") }),
      password: z.string().min(6, {
        message: t("passwordInvalid"),
      }),
      new_password: z.string().min(6, {
        message: t("newPasswordInvalid"),
      }),
    })
    .refine((data) => data.password !== data.new_password, {
      message: t("newAndOldPasswordMatch"),
      path: ["new_password"],
    });

export type UpdateProfilePasswordFormData = z.infer<
  ReturnType<typeof UpdateProfilePasswordSchema>
>;
